<?php

/**
 * @file
 * Definition of example_handler_custom_field
 */

/**
 * Provides a custom views field.
 */
class jessica_stylebook_handler_style_thumbnail_item_brand extends views_handler_field {
    function option_definition() {
        $options = parent::option_definition();
        return $options;
    }

    function options_form(&$form, &$form_state) {
        parent::options_form($form, $form_state);
    }

    function query() {
        // do nothing -- to override the parent query.
    }

    function render($data) {
        //dsm($data, 'data');
        $items = $data->field_field_styling_item;


        foreach ($items as $key => $item) {
            //dpm($item, 'item');

            $fc_item = reset($item['rendered']['entity']['field_collection_item']);
            if (isset($fc_item['field_styling_item_id'])) {
                $item_entity = $fc_item['field_styling_item_id']['#items'][0]['entity'];
                $fc_entity = $fc_item['#entity'];

                //dpm($fc_entity, '$fc_entity');

                if ($fc_entity->field_pin_show_on_thumbnail['und'][0]['value']) {
                    //dpm($item_entity, '$item_entity');

                    $brand = taxonomy_term_load($item_entity->field_item_brand['und'][0]['tid']);
                    return $brand->name;
                }
            }
        }

        return '';
    }
}

